//
//  BroadcastBusInterface.h
//  sad
//
//  Created by Christopher Kemsley on 5/3/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef sad_BroadcastBusInterface_h
#define sad_BroadcastBusInterface_h

#include "SystemCDefinitions.hpp"


#define	BroadcastBusNamespaceBegin	namespace BroadcastBus {
#define	BroadcastBusNamespaceEnd	}

BroadcastBusNamespaceBegin

using namespace SystemC ;




typedef UInt32	Identifier ;
typedef UInt32	Length ;
typedef UInt64	Datum ;


enum {
	kFlagNoResponse				=	0 ,
	kFlagReceivedAcceptance		=	1 ,	// At least somebody wants it
	kFlagReceivedObjection		=	2	// At least somebody objected
} ;
typedef UInt8	Flags ; // bitwise-or of the above




struct	PublicationInfo
{
	PublicationInfo () ;
	PublicationInfo ( Identifier topicID , Length burstLength ) ;
	PublicationInfo ( PublicationInfo const & copy ) ;
	~PublicationInfo () ;
	
	void	operator=	( PublicationInfo const & copy ) ;
	bool	operator==	( PublicationInfo const & compare ) ;
	
	
	Identifier	topicIdentifier () const ;
	Length		burstLength () const ;
	
	Identifier	uniqueID () const ;
	
	
	bool		isValid () const ;
	void		invalidate () ;
	
	
private:
	Identifier	mTopicID ;
	Length		mLength ;
	Identifier	mUniqueID ;
	
	static Identifier	newUniqueID () ;
} ;









class	PublisherInterface : virtual public sc_interface
{
public:
	virtual Flags	enqueueBroadcastAndWait	( PublicationInfo const & info ) = 0 ;
	
	virtual void	commitWriteOperation () = 0 ;
	
	virtual void	write ( Datum datum ) = 0 ;
} ;









class	SubscriberInterface : virtual public sc_interface
{
public:
	virtual void	waitForPublicationInfo ( PublicationInfo & outInfo ) = 0 ;
	
	virtual void	acknowledgePublication () = 0 ;
	virtual void	raiseObjection () = 0 ;
	
	virtual void	read ( Datum & datum ) = 0 ;
} ;






BroadcastBusNamespaceEnd

#endif
